package com.springredis.dao;

import com.springredis.pojo.Book;
import jakarta.annotation.Resource;
import java.util.*;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;
@SuppressWarnings("unchecked")
@Repository
public class BookDao {
	@Resource
	private RedisTemplate redisTemplate;
	@Resource
	private StringRedisTemplate stringRedisTemplate;
	public void setValue(String key, String value){
		stringRedisTemplate.opsForValue().set(key, value);
	}
	public String getValue(String key){
		return stringRedisTemplate.opsForValue().get(key);
	}
	public List<Book> findBooks(String id){
		return (List<Book>) redisTemplate.opsForValue().get(id);
	}
	public void saveBooks(Object key,List<Book> books){
		redisTemplate.opsForValue().set(key,books);
	}
	public Book findBookById(int id){
		return (Book) redisTemplate.opsForValue().get(String.valueOf(id));
	}
	public void saveBook(Book book){
		redisTemplate.opsForValue().set(String.valueOf(book.getId()), book);
	}
	public void deleteBook(int id){
		redisTemplate.delete(String.valueOf(id));
	}
}
